package com.sunjob.mrotech.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.sunjob.common.domain.tech.InsertShapeCompositionVO;
import com.sunjob.common.domain.tech.TransShape2;
import com.sunjob.common.domain.tech.TransShape3;
import com.sunjob.common.domain.tech.TransShapeComposition;
import com.sunjob.common.mroAnno.ControllerLog;
import com.sunjob.common.mroAnno.LogModuleType;
import com.sunjob.common.result.Result;
import com.sunjob.mrotech.server.ShapeServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : xiaozhoutongxue
 * @date : 2022/8/2 14:16
 */
@Api(tags = "构型处理")
@RestController
@CrossOrigin
public class ShapeController {
    @Autowired
    ShapeServer shapeServer;

    @ApiOperation("增加构型实例")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PostMapping("/insertShapeComposition")
    public Result insertShapeComposition(@RequestBody InsertShapeCompositionVO ins){
        return shapeServer.insertShapeComposition(ins);
    }

    @ApiOperation("增加二级构型")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PostMapping("/insertShape2")
    public Result insertShape2(@RequestBody TransShape2 com2){
        Boolean flag=shapeServer.insertShape2(com2);
        return flag ? Result.ok(null, "二级构型增加成功") : Result.fail("二级构型增加失败");
    }

    @ApiOperation("增加三级构型")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PostMapping("/insertShape3")
    public Result insertShape3(@RequestBody TransShape3 com3){
        Boolean flag=shapeServer.insertShape3(com3);
        return flag ? Result.ok(null, "三级构型增加成功") : Result.fail("三级构型增加失败");
    }

    @ApiOperation("查找所有构型")
    @GetMapping("/getAllShape")
    public Result getAllShape(@RequestParam(value = "limit",required = false, defaultValue= "0")int limit){
        return Result.ok(shapeServer.getAllShape(limit),"odk");
    }


    @ApiOperation("模糊查找一级构型名和id")
    @GetMapping("/getShapeByLittle")
    public Result getShapeByLittle(@RequestParam String little){
        return Result.ok(shapeServer.getShapeByLittle(little),"odk");
    }

    @ApiOperation("根据id查找一级以下的所有结构")
    @GetMapping("/getshapeCompositionById")
    public Result getShapeCompositionById(@RequestParam("id") Long id){
        return shapeServer.getshapeCompositionById(id);
    }

    @ApiOperation("根据id查找一级以下的二级结构")
    @GetMapping("/getShape2CompositionById")
    public Result getShape2CompositionById(@RequestParam("id") Long id){
        return shapeServer.getShape2CompositionById(id);
    }

    @ApiOperation("根据一级和二级结构id查找所属的所有三级结构")
    @GetMapping("/getShapa3CompositionByShape2Id")
    public Result getShapa3CompositionByShape2Id(@RequestParam("shapeId") Long shapeId,@RequestParam("shape2Id") Long shape2Id){
        return shapeServer.getShapa3CompositionByShapeIdAndShape2Id(shapeId,shape2Id);
    }
    //@SaCheckPermission(value = {"tech:shape2:query"})
    @ApiOperation("查找所有二级结构")
    @GetMapping("/getAllShapa2Composition")
    public Result getAllShapa2Composition(){
        return shapeServer.getAllShapa2Composition();
    }

    @ApiOperation("只跟据二级id查找所有三级结构")
    @GetMapping("/getAllShapa3Composition")
    public Result getAllShapa3Composition(@RequestParam Long shape2Id){
        return shapeServer.getAllShapa3Composition(shape2Id);
    }

    @ApiOperation("更新操作（仅仅支持更新三级构型）")
    @PostMapping("/updateShape3")
    public Result updateShape3(@RequestParam Long shape_id,@RequestParam Long shape2_id,@RequestParam Long shape3_id,int isNew){
        return shapeServer.upadateShape3Composition(shape_id,shape2_id,shape3_id,isNew);
    }
    @ApiOperation("/删除一个构型")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @GetMapping("/deleteShapeById")
    public Result deleteShapeById(@RequestParam Long id){
        return shapeServer.deleteShapeById(id);
    }


}
